import java.sql.*;
public class ManageMysqlDB {
	
	public Connection conn=null;
	public Statement stmt=null;
	public ResultSet rs=null;
	int effectRows=0;
	
	public void connectionDB(String user,String password) {
		try {
			Class.forName("com.mysql.jdbc.Driver");
			conn=DriverManager.getConnection("jdbc:mysql://120.79.79.93:3306/javaCourse?useSSL=false&user=root&password=X198x107b");
		} catch (ClassNotFoundException e) {
			System.out.println("错误");
			e.printStackTrace();
		} catch (SQLException e) {
			System.out.println("错误");
			e.printStackTrace();
		}
		
	}
	
	public ResultSet queryDB(String sql) {
		try {
			stmt=conn.createStatement();
			rs=stmt.executeQuery(sql);
		} catch (SQLException e) {
			System.out.println("错误");
			e.printStackTrace();
		}
		return rs;
	}
	
	public int updateDB(String sql) {
		try {
			stmt=conn.createStatement();
			effectRows=stmt.executeUpdate(sql);
		} catch (SQLException e) {
			System.out.println("错误");
			e.printStackTrace();
		}
		return effectRows;
	}
	
	public void closeDB() {
		try
        {
            if(rs!=null)rs.close();
            if(stmt!=null)stmt.close();
            if(conn!=null)conn.close();
        }catch(SQLException e)
        {
        	System.out.println("错误");
        	e.printStackTrace();
        }
	}
}
